package cn.edu.buaa.cnsatm.traffic_big_data_server.division.service;

import cn.edu.buaa.cnsatm.traffic_big_data_server.division.dao.TheaterDivisionDAO;
import com.google.gson.JsonObject;
import com.google.gson.JsonArray;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @name = LX
 * @classname = TheaterDivisionController
 * @description = 战区区划相应接口
 * @date = 2019/10/23
 */
public class TheaterDivisionService {
    public static String getTheaterDivisionByLonAndLa(Double longitude, Double latitude) throws SQLException {
        ResultSet resultSet = TheaterDivisionDAO.getProvinceByLonAndLa(longitude, latitude);
        resultSet.next();
        String provinceName = resultSet.getString("name");
        String theaterDivisionName = resultSet.getString("theater_division");
        resultSet.getStatement().close();
        resultSet.close();
        /*转json*/
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("province",provinceName);
        jsonObject.addProperty("theater_division",theaterDivisionName);
        return jsonObject.toString();
    }
    public static String getProvinceByLonAndLa(Double longitude, Double latitude) throws SQLException {
        ResultSet resultSet = TheaterDivisionDAO.getProvinceByLonAndLa(longitude, latitude);
        resultSet.next();
        String provinceName = "";
        try{
            provinceName = resultSet.getString("name");
        }catch (Exception e){
            provinceName = "未知";
        }
        resultSet.getStatement().close();
        resultSet.close();
        return provinceName;
    }



}
